import store from './store.js';
import { addToCart,addToCartAsync, updateCart, deleteFromCart} from './actions/cart-actions'

import React from 'react'
import ReactDOM from 'react-dom'
import {Provider} from 'react-redux' 

console.log("购物车初始状态", store.getState())

// subscribe 订阅
let unsubscribe = store.subscribe(()=>{
  console.log("操作了购物车", store.getState());
})




store.dispatch(addToCart('Coffee 500g', 1, 250));
store.dispatch(addToCartAsync('Flour 1kg', 2, 110))
store.dispatch(updateCart('Flour 1kg', 3, 220))
store.dispatch(deleteFromCart('Flour 1kg'))

unsubscribe();

const App = <h1> redux Shopping Cart </h1>



ReactDOM.render(
  <Provider store={store}>
    { App }
  </Provider>,
  document.getElementById('root')
)
